let writeData = require('../Component/writeData');

describe('writeData()', () => {

    it('If the data is correctly written to the user data', () => {
        let customerList = {
            "A": {
                "2017-08-01": {
                    "today": "workday",
                    "usedTime": ["9:00~13:00"],
                    "cancelled": ["19:00~22:00"],
                    "U003": ["9:00~13:00"]
                }
            }
        };
        let data = {
            user: 'U004',
            date: '2017-08-02',
            time: '9:00~13:00',
            space: 'A'
        };
        let actual = writeData.writeData(customerList,data);
        let result ={
            "A": {
                "2017-08-01": {
                    "today": "workday",
                    "usedTime": ["9:00~13:00"],
                    "cancelled": ["19:00~22:00"],
                    "U003": ["9:00~13:00"]
                },
                "2017-08-02": {
                    "today": "workday",
                    "usedTime": ["9:00~13:00"],
                    "U004": ["9:00~13:00"]
                }
            }
        };
        expect(JSON.stringify(actual)).toBe(JSON.stringify(result));
    });
    it('The user\'s scheduled time conflicts with the previous time should return message', () => {
        let customerList = {
            "A": {
                "2017-08-01": {
                    "today": "workday",
                    "usedTime": ["9:00~13:00"],
                    "cancelled": ["19:00~22:00"],
                    "U003": ["9:00~13:00"]
                }
            }
        };
        let data = {
            user: 'U004',
            date: '2017-08-01',
            time: '9:00~13:00',
            space: 'A'
        };
        let actual = writeData.writeData(customerList,data);
        let result ="Error: the booking conflicts with existing bookings!";
        expect(actual).toBe(result);
    });
});